package com.project.bohang.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.project.bohang.common.model.Response;
import com.project.bohang.common.model.page.PageResult;
import com.project.bohang.entity.EsGoods;
import com.project.bohang.entity.Visit;
import com.project.bohang.pojo.dto.EsGoodsDto;
import com.project.bohang.pojo.dto.SendEsGoodsDto;
import com.project.bohang.pojo.dto.VisitDto;
import com.project.bohang.pojo.vo.VisitVo;
import com.project.bohang.service.EsGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import com.project.bohang.controller.BaseController;

/**
 *  疫情防疫物品管理(管理员)
 *
 * @author bohang
 * @since 2022-03-26
 */
@Controller
@RequestMapping("/esGoods")
@ResponseBody
public class EsGoodsController extends BaseController {

    @Autowired
    private EsGoodsService esGoodsService;

    /**
     * 疫情防疫物品列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public Response<PageResult<EsGoods>> selectList(@RequestBody EsGoodsDto dto){
        return Response.success(getDataTable(esGoodsService.selectList(dto)));
    }

    /**
     * 新增疫情防疫物品信息
     *
     * @param req
     * @return
     */
    @PostMapping("/save")
    public Response save(@RequestBody EsGoods req) {
        esGoodsService.save(req);
        return Response.success();
    }


    /**
     * 修改疫情防疫物品信息
     *
     * @param req
     * @return
     */
    @PostMapping("/update")
    public Response update(@RequestBody EsGoods req) {
        UpdateWrapper<EsGoods> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", req.getId());
        esGoodsService.update(req, updateWrapper);
        return Response.success();
    }

    /**
     * 删除疫情防疫物品
     *
     * @param req
     * @return
     */
    @PostMapping("/del")
    public Response del(@RequestBody EsGoods req) {
        EsGoods entity = new EsGoods();
        entity.setId(req.getId());
        entity.setDeleted("1");
        esGoodsService.updateById(entity);
        return Response.success();
    }

    /**
     * 疫情防疫物品信息详情
     *
     * @param req
     * @return
     */
    @PostMapping("/detail")
    public Response<EsGoods> detail(@RequestBody EsGoods req) {
        EsGoods entity = esGoodsService.getById(req.getId());
        return Response.success(entity);
    }

    /**
     * 疫情防疫物品发放
     *
     * @param req
     * @return
     */
    @PostMapping("/send")
    public Response send(@RequestBody SendEsGoodsDto req) {
        return esGoodsService.send(req);
    }


}

